﻿namespace SVNWrapper
{
    using SharpSvn;
    using System;
    using System.Collections.Generic;
    using System.Runtime.InteropServices;

    public class SVN
    {
        public static bool GetLog(string targetURL, out List<SVNLogData> logOutput)
        {
            Uri uri;
            EventHandler<SvnLogEventArgs> logHandler = null;
            logOutput = new List<SVNLogData>();
            List<SVNLogData> aux = new List<SVNLogData>();
            if (!(!string.IsNullOrEmpty(targetURL) && Uri.TryCreate(targetURL, UriKind.Absolute, out uri)))
            {
                return false;
            }
            SvnClient client = new SvnClient();
            try
            {
                if (logHandler == null)
                {
                    logHandler = delegate (object lSender, SvnLogEventArgs le) {
                        SVNLogData item = new SVNLogData(le.Author, le.LogMessage, le.Revision, le.Time);
                        aux.Add(item);
                    };
                }
                client.Log(uri, logHandler);
                logOutput.AddRange(aux);
            }
            catch (Exception)
            {
                return false;
            }
            finally
            {
                if (client != null)
                {
                    client.Dispose();
                }
            }
            return true;
        }
    }
}

